<template>
  <!--
    用户信息
   1：封装api请求
   2:导入api
   3:进入页面就请求created
   4:存储数据并渲染
 -->

  <div class="mine">
    <div class="top">
      <img class="avatar" :src="userInfo.photo" alt="" />
      <div class="right">
        <div class="name">{{ userInfo.name }}</div>
        <div class="date">{{ userInfo.birthday }}</div>
      </div>
    </div>
    <div class="middle">
      <div class="item">
        <van-icon name="newspaper-o" color="#a4b1ff" />
        <div class="title">我的作品</div>
      </div>
      <div class="item">
        <van-icon name="star-o" color="#ff3803" />
        <div class="title">我的收藏</div>
      </div>
      <div class="item">
        <van-icon name="tosend" color="#ffb355" />
        <div class="title">阅读历史</div>
      </div>
    </div>
    <div class="bottom">
      <van-cell-group>
        <van-cell title="编辑资料" is-link icon="edit" to="/mineEdit" />
        <van-cell title="小智同学" is-link icon="chat-o" to="/chat" />
        <van-cell title="系统设置" is-link icon="setting-o" />
        <van-cell title="退出登录" is-link icon="info-o" @click="exit" />
        <!-- 退出登录：
              1：先来一个确定框（退出，删除）
              2：删除token,删除用户信息
              3：跳转到登陆页
              4：提示

        -->
      </van-cell-group>
    </div>
  </div>
</template>
<script>
// import { userProfile } from '@/api/mine'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      xxx: '96'
    }
  },
  computed: {
    ...mapState('user', ['userInfo'])
  },
  async created () {
    // 获取用户信息
    this.$store.dispatch('user/getUserInfo')
    // const res = await userProfile()
    // this.$store.commit('user/setUserInfo', res.data)
    // console.log('用户信息', res)
  },
  methods: {
    // 退出登录
    exit () {
      this.$dialog
        .confirm({
          title: '温馨提示',
          message: '您确定退出该网站吗'
        })
        .then(() => {
          this.$store.commit('user/logout')
          this.$router.push('/login')
          this.$toast.success('退出登录成功')
          console.log('点击了确定')
        })
        .catch(() => {
          console.log('点击了取消')
        })
    }
  }
}
</script>
<style lang="less" scoped>
.mine {
  .top {
    padding: 20px;
    background-color: #3296fa;
    display: flex;
    align-items: center;
    .avatar {
      width: 75px;
      height: 75px;
      border-radius: 50%;
      object-fit: cover;
      margin-right: 15px;
      //   background-size:cover/contain
    }
    .right {
      color: #fff;
      .name {
        font-size: 18px;
        font-weight: 600;
        margin-bottom: 8px;
      }
      .date {
        font-size: 18px;
        background-color: #fff;
        color: #6096fa;
      }
    }
  }
  .middle {
    padding: 15px 0;
    display: flex;
    justify-content: space-evenly;
    .item {
      text-align: center;
      .van-icon {
        font-size: 30px;
        margin-bottom: 12px;
      }
      .title {
        font-size: 18px;
      }
    }
  }
}
</style>
